package com.j283_5.wisdom_park.controller.project_admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.j283_5.wisdom_park.common.result.ResultData;
import com.j283_5.wisdom_park.service.DeviceInformationService;
import com.j283_5.wisdom_park.service.MaintenanceRecordService;
import com.j283_5.wisdom_park.service.WarningRecordService;
import com.j283_5.wisdom_park.vo.device_management.DeviceInformationVo;
import com.j283_5.wisdom_park.vo.maintenance_management.MaintenanceDeliveryVo;
import com.j283_5.wisdom_park.vo.maintenance_management.MaintenanceVo;
import com.j283_5.wisdom_park.vo.project_admin.WarningInformationVo;
import com.j283_5.wisdom_park.vo.warning_management.WarningDeliveryVo;
import com.j283_5.wisdom_park.vo.warning_management.WarningVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author laoda
 * @since 2022-04-28
 */
@Transactional
@RestController
@RequestMapping("/projectAdmin")
@Api(value = "工程管理员",tags = "工程管理员",produces="王银伟")
public class ProjectAdminController {
    @Resource
    private DeviceInformationService deviceInformationService;
    @Resource
    private WarningRecordService warningRecordService;
    @Resource
    private MaintenanceRecordService maintenanceRecordService;

    @RequestMapping(value = "/deviceProject" , method = RequestMethod.POST)
    @ApiOperation(value = "查询该管理员管理的设备信息",notes = "查询该管理员管理的设备信息（分页）",produces="王银伟", response = ResultData.class)
    public ResultData deviceProjectList(@Param("page") Page<DeviceInformationVo> page,@Param("deviceInformationVo") DeviceInformationVo deviceInformationVo,Integer adminId){
        //将需要模糊查询的条件存储到map中
        Map<String,Object> map = new HashMap();

        List<DeviceInformationVo> deviceInformationVoList = deviceInformationService.queryDeviceInformation(page, deviceInformationVo,adminId);
        Integer sum = deviceInformationService.queryDeviceCount(deviceInformationVo,adminId);

        if (!(deviceInformationVoList != null && deviceInformationVoList.size() > 0)){
            return ResultData.error();
        }
        map.put("deviceInformationVoList",deviceInformationVoList);
        map.put("sum",sum);
        return ResultData.error().message("1");
//        return ResultData.ok().data(map);
    }
    @RequestMapping(value = "/deliveryInformation" , method = RequestMethod.POST)
    @ApiOperation(value = "获取需要预警设备的基本信息",notes = "获取需要预警设备的基本信息",produces="王银伟", response = ResultData.class)
    public ResultData deliveryInformation(Integer dinfId){
        return ResultData.ok().data(deviceInformationService.queryOneDevice(dinfId));
    }


    @RequestMapping(value = "/deviceAddWarning" , method = RequestMethod.POST)
    @ApiOperation(value = "设备告警",notes = "设备告警",produces="王银伟", response = ResultData.class)
    public ResultData deviceAddWarning(Integer dinfId,WarningDeliveryVo warningDeliveryVo){
        if (warningRecordService.addWarningDelivery(dinfId, warningDeliveryVo)){
            return ResultData.ok().data("设备告警成功");
        }
        return ResultData.error().message("设备告警失败");
    }



    @RequestMapping(value = "/deliveryWarning" , method = RequestMethod.POST)
    @ApiOperation(value = "查询维修的设备信息",notes = "查询维修的设备信息（分页）",produces="王银伟", response = ResultData.class)
    public ResultData deliveryWarning(@Param("page") Page<WarningInformationVo> page, @Param("warningVo") WarningVo warningVo,Integer adminId){
        //将需要模糊查询的条件存储到map中
        Map<String,Object> map = new HashMap();

        List<WarningVo> warningVoList = warningRecordService.queryWarningSum(page, warningVo,adminId);

        if (!(warningVoList != null && warningVoList.size() > 0)){
            return ResultData.error();
        }

        Integer sum = warningRecordService.queryWarningCount(warningVo,adminId);
        map.put("warningVoList",warningVoList);
        map.put("sum",sum);
        return ResultData.ok().data(map);
    }
    @RequestMapping(value = "/warningDeliveryInformation" , method = RequestMethod.POST)
    @ApiOperation(value = "获取维修设备的详细信息",notes = "获取维修设备的详细信息",produces="王银伟", response = ResultData.class)
    public ResultData warningDelivery(Integer wrecId){
        return ResultData.ok().data(warningRecordService.queryWarningDelivery(wrecId));
    }

    @RequestMapping(value = "/warningDeliveryUpload" , method = RequestMethod.POST)
    @ApiOperation(value = "提交维修设备信息",notes = "提交维修设备信息",produces="王银伟", response = ResultData.class)
    public ResultData handelWarningUpload(WarningDeliveryVo warningDeliveryVo){
        if (warningRecordService.updateWarningDelivery(warningDeliveryVo)){

            return ResultData.ok().data("维修成功");
        }
        return ResultData.error().message("维修失败");
    }


    @RequestMapping(value = "/maintenanceDevice" , method = RequestMethod.POST)
    @ApiOperation(value = "查询运维信息",notes = "查询运维信息（分页）",produces="王银伟", response = ResultData.class)
    public ResultData maintenanceDevice(@Param("page") Page<DeviceInformationVo> page, @Param("maintenanceVo") MaintenanceVo maintenanceVo,Integer adminId){
        //将需要模糊查询的条件存储到map中
        Map<String,Object> map = new HashMap();

        List<MaintenanceVo> maintenanceVoList = maintenanceRecordService.queryAllMaintenance(page, maintenanceVo,adminId);

        if (!(maintenanceVoList != null && maintenanceVoList.size() > 0)){
            return ResultData.error();
        }


        Integer sum = maintenanceRecordService.queryMaintenanceCount(maintenanceVo,adminId);

        map.put("maintenanceVoList",maintenanceVoList);
        map.put("sum",sum);

        return ResultData.ok().data(map);

    }

    @RequestMapping(value = "/maintenanceDeviceInformation" , method = RequestMethod.POST)
    @ApiOperation(value = "查询运维详情信息",notes = "查询运维详情信息",produces="王银伟", response = ResultData.class)
    public ResultData maintenanceDeviceInformation(Integer mrecId){
        return ResultData.ok().data(maintenanceRecordService.queryMaintenanceDelivery(mrecId));
    }

    @RequestMapping(value = "/maintenanceDeviceUpload" , method = RequestMethod.POST)
    @ApiOperation(value = "运维设备",notes = "运维设备",produces="王银伟", response = ResultData.class)
    public ResultData maintenanceDeviceUpdate(@Param("maintenanceDeliveryVo")MaintenanceDeliveryVo maintenanceDeliveryVo){
        if (maintenanceRecordService.updateMaintenanceDelivery(maintenanceDeliveryVo)){
            return ResultData.ok().data("运维成功");
        }
        return ResultData.error().message("运维失败");
    }
}
